package cn.java81.jdbc;

import cn.java81.util.DbUtil;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class StudentResult {
    //滚动结果集
    public static void main(String[] args) {

        //占位符的方案：错误
        String sql = "select * from s_student order by stuno desc";

        Connection connection = DbUtil.getConnection();
        PreparedStatement st = null;
        ResultSet rs = null;
        try {
            st = connection.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            rs=st.executeQuery();
            for (int i = 0; i <20&&rs.next() ; i++) {
                System.out.println("学号："+rs.getLong("stuno"));
               String name=rs.getString("sname");
               String qq=rs.getString("qq");
                //Date enterdate = rs.getDate("enterdate");
                Timestamp enterdate = rs.getTimestamp("enterdate");
                System.out.println(name+","+qq+","+enterdate);
            }
            rs.previous();
            rs.previous();
            rs.previous();
            System.out.println("----第17个");
            System.out.println("学号："+rs.getLong("stuno")+","+rs.getString("sname"));
            //直接去100
            rs.absolute(100);
            System.out.println("第100个");
            System.out.println("学号："+rs.getLong("stuno")+","+rs.getString("sname"));

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DbUtil.close(rs, st, connection);
        }

    }
}
